package com.zp.pattern.composite1;

import java.util.ArrayList;
import java.util.List;
/**
 * 组合类：
 * (1)定义有子节点（子部件）的部件的行为;
 * (2)存储子节点（子部件）;
 * (3)在Component接口中实现与子部件相关的操作;
 */
public class Composite implements Component
{
	private List<Component> list = new ArrayList<Component>();
	
	public void add(Component component)
	{
		list.add(component);
	}
	
	public void remove(Component component)
	{
		list.remove(component);
	}
	
	public List<Component> getAll()
	{
		return this.list;
	}
	
	@Override
	public void doSomething()
	{
		for(Component component : list)
		{
			component.doSomething();
		}
	}
}
